<?php
/**
 * Created by PhpStorm.
 * User: Kaguya
 * Date: 2015/5/23
 * Time: 20:40
 */

//include("../dbConn.php");
$postJson = $_POST['hook'];
$post=json_decode($postJson,true);
if($post['password']=="kaguya"){
    //$data = array();
   // $time = date('Y-m-d-H-i-s');
    //$data=json_encode($_POST);
    //$Conn = dbConn();
    //$sql = "insert into linshiceshi (content,time) values ('$data','$time')";
    //$re=mysql_query($sql,$Conn);
    //var_dump($_POST['hook']);
    $data = $post['push_data'];
    $ref = $data["ref"];
    $arr = array();
    $arr = explode("/",$ref);
    $num = count($arr);
    $branch = $arr[$num-1];
    switch($branch){
        case "dev":
            system("bash /root/sh/git-synapse-dev.sh");
            echo "dev";
            break;
        case "master":
            system("bash /root/sh/git-synapse.sh");
            echo "master";
            break;
        default:

    }
    //var_dump($arr);

}else{
    $res=system("bash /root/sh/git-synapse.sh");
    echo "ERROR:".$res;
}

//var_dump($_POST);